<?php
/*
	名片基本信息编辑
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
cfc('core')->checklogin();
if($_RQ['op']=='main'){
	$item=$this->get('card',array('mid'=>$_SESSION['uid']));
	if(!$item){
		$member=pdo_get('core_members',array('id'=>$_SESSION['uid']),array('avatar','mobile','wechat'));
		$item=array('mobile'=>$member['mobile'],'avatar'=>$member['avatar'],'wechat_name'=>$member['wechat']);
	}
	$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$data=array_fields(array('name','avatar','company','department','position','mobile','email','wechat_name','address','qq_name','attention','find','industry','qianming'),$post);
	$id=intval($post['id']);
	if($id){
		$this->update('card',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['mid']=$_SESSION['uid'];
		$data['ewm']=cfc('tools')->createqrcode(custom_url('jy_business_card/index//mid='.$_SESSION['uid'],true),150,true);
		$data['createtime']=TIMESTAMP;
		$this->insert('card',$data);
		$member_secret=array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']);
		$basic=$this->plugin_setting('basic');
		if($basic['is_fee'] && $basic['mofee']>0){
			$member_secret['mobile_fee']=$basic['mofee'];
			$member_secret['email_fee']=$basic['mofee'];
			$member_secret['address_fee']=$basic['mofee'];
			$member_secret['wechat_fee']=$basic['mofee'];
			$member_secret['qq_fee']=$basic['mofee'];
		}
		$this->insert('member_secret',$member_secret);
	}
	exi('设置成功！','','index/');
}